{include file="common/head"/}
<div class="admin-main fadeInUp animated">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <input TYPE="hidden" name="id" value="{$record.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">请选择模型</label>
            <div class="layui-input-3">
                <select name="moduleid" lay-verify="required" lay-filter="moduleid" id="moduleid">
                    {volist name="modulelist" id="vo"}
                    <option value="{$vo.id}" {if condition="$module eq $vo['id']"}selected{/if}>{$vo.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上级栏目</label>
            <div class="layui-input-3">
                <select name="pid" id="pid">
                    <option value="">作为一级栏目</option>
                    {$categorys|raw}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">栏目名称</label>
            <div class="layui-input-4">
                <input type="text" name="catname" lay-verify="required" value="{$record.catname}" placeholder="{:lang('pleaseEnter')}栏目名称" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux red">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">栏目目录</label>
            <div class="layui-input-4">
                <input type="text" name="catdir" lay-verify="required" value="{$record.catdir}" placeholder="{:lang('pleaseEnter')}栏目目录" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux red">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">栏目图片</label>
            <input type="hidden" name="image" id="image" value="{$record['image']}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="cateBtn"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" src="{$record['imgUrl']}" id="cateImage">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">SEO标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{$record.title}" placeholder="{:lang('pleaseEnter')}SEO标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">SEO关键字</label>
            <div class="layui-input-block">
                <textarea placeholder="{:lang('pleaseEnter')}SEO关键字" name="keywords" class="layui-textarea">{$record.keywords}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">SEO描述</label>
            <div class="layui-input-block">
                <textarea placeholder="{:lang('pleaseEnter')}SEO描述" name="description" class="layui-textarea">{$record.description}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">多栏目设置</label>
            <div class="layui-input-1">
                <input type="checkbox" name="child" value="1" {if condition="$record['child'] eq 1"} checked{/if} lay-skin="switch" title="多栏目设置">
            </div>
            <div class="layui-form-mid layui-word-aux">打开后，其下将不能添加内容。</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">导航</label>
            <div class="layui-input-block">
                <input type="radio" name="ismenu" lay-filter="is_open" checked value="1" {if condition="$record['ismenu'] eq 1"}checked{/if} title="{:lang('yes')}">
                <input type="radio" name="ismenu" lay-filter="is_open" value="0" {if condition="$record['ismenu'] eq 0"}checked{/if} title="{:lang('no')}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">预览</label>
            <div class="layui-input-block">
                <input type="radio" name="is_show" lay-filter="is_show" checked value="1" {if condition="$record['is_show'] eq 1"}checked{/if} title="开启">
                <input type="radio" name="is_show" lay-filter="is_show" value="0" {if condition="$record['is_show'] eq 0"}checked{/if} title="关闭">
            </div>
        </div>
        {if session('aid') eq 1}
        <div class="layui-form-item">
            <label class="layui-form-label">访问权限</label>
            <div class="layui-input-block">
                {volist name="rlist" id="item" key="i"}
                <input type="checkbox" {if condition="in_array($item['group_id'],$record['readgroup'])"}checked{/if} name="readgroup[{$i}]" value="{$item.group_id}" title="{$item.title}">
                {/volist}
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">分页条数</label>
                <div class="layui-input-inline">
                    <input type="number" name="pagesize" value="{$record.pagesize}" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">为空时默认值为系统设置的值</div>
            </div>
        </div>

        <div class="layui-form-item tlist">
            <label class="layui-form-label">列表页模板</label>
            <div class="layui-input-3">
                <select name="template_list" id="template_list">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容页模板</label>
            <div class="layui-input-3">
                <select name="template_show" id="template_show">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script src="/static/common/js/jquery.2.1.1.min.js"></script>
<script>
    var modulearr = new Array();
    {volist name="modulelist" id="mdate"}
    modulearr[{$mdate['id']}] = "{$mdate['name']}";
    {/volist}
    var templatearr = new Array();
    {volist name="templates" id="tem"}
    templatearr[{$i}] = "{$tem['value']},{$tem['filename']}";
    {/volist}
    var datas = "<option value=''>请选择</option>";
    var moduleid =  $('#moduleid').val();
    var image = '{$record.image}';

    layui.use(['form','upload'], function () {
        var form = layui.form,upload = layui.upload;

        var uploadInst = upload.render({
            elem: '#cateBtn'
            ,url: '{:url("UpFiles/upload")}',
            done: function(res){
                if(res.code>0){
                    $('#image').val(res.url);
                    $('#cateImage').attr('src', res.url);
                }else{
                    return layer.msg('上传失败');
                }
            },
            error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        form.on('submit(submit)', function (data) {
            // 提交到方法 默认为本身
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('catUpdate')}", data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        });
        form.on('select(moduleid)', function(data){
            showtemplist(data.value,0,form);
        });
    });
    function showtemplist(m,t,form){

        var type='_list';
        if(t){
            type='_index';
        }
        var mtlist = modulearr[m]+type;
        var mtshow = modulearr[m]+'_show';

        if(modulearr[m]=='page'){
            $('.tlist').hide();
            mtlist=mtshow ='page';
        }else{
            $('.tlist').show();
        }
        $('#template_list').html(datas);
        $('#template_show').html(datas);

        listdatas = showdatas ='';
        for(i=1;i<templatearr.length;i++){
            data = templatearr[i].split(',');
            if(data[0].indexOf(mtlist)  >= 0){
                listdatas  ="<option value='"+data[0]+"'>"+data[1]+"</option>";
                $('#template_list').append(listdatas);
            }
            if(data[0].indexOf(mtshow)  >= 0){
                showdatas ="<option value='"+data[0]+"'>"+data[1]+"</option>";
                $('#template_show').append(showdatas);
            }
        }
        $("#template_list").val('{$record.template_list}');
        $("#template_show").val('{$record.template_show}');
        if(form){
            form.render()
        }
    }
    showtemplist(moduleid,{if condition="empty($record['listtype'])"}0{else /}{$record.listtype}{/if});
    function templatetype(){
        var moduleid = $('#moduleid').val();
        if($("#listtype").attr('checked')==true){
            showtemplist(moduleid,1);
        }else{
            showtemplist(moduleid,0);
        }
    }
</script>